import axios from "axios";

axios.interceptors.request.use(function (config) {
    // 请求发送之前
    console.log(config);
    return config;
}, function (error) {
    // Do something with request error
    return Promise.reject(error);
});


axios.interceptors.response.use(function (config) {
    // 请求发送之后
    console.log(config);
    return config;
}, function (error) {
    // Do something with response error
    return Promise.reject(error);
});


export function request(type, url, data) {
    if (data) {
        return axios[type](url, JSON.stringify(data));
    } else {
        return axios[type](url);
    }
}

const localID = "http://localhost:9000";
export function uploadFile(url, data) {
    return axios.post(localID + url, data);
}

export function Post(url, data = {}) {
    return axios.post(localID + url, JSON.stringify(data));
}

export function Get(url, data = {}) {
    return axios.get(localID + url, {
        params: data
    });
}